#ifndef CHATDIALOG_H
#define CHATDIALOG_H

#include <QDialog>
#include<vector>
#include<QList>
#include<QMouseEvent>
#include<QEvent>
#include<QListWidgetItem>
#include"global.h"
#include"statewidget.h"
#include"userdata.h"
namespace Ui {
class ChatDialog;
}

class ChatDialog : public QDialog
{
    Q_OBJECT

public:
    explicit ChatDialog(QWidget *parent = nullptr);
    ~ChatDialog();

protected:
    bool eventFilter(QObject *watched, QEvent *event)override;
private:
    Ui::ChatDialog *ui;

    void ShowSearch(bool bsearch);
    ChatUIMode _mode;
    ChatUIMode _state;
    int _cur_chat_uid;
    bool _b_loading;
    QWidget* _last_widget;
    void addChatUserList();
    void AddLBGroup(StateWidget*);
    void ClearLabelState(StateWidget*);
    void SetSelectChatItem(int uid=0);
    void SetSelectChatPage(int uid=0);
    void loadMoreChatUser();
    void loadMoreConUser();
    void UpdateChatMsg(std::vector<std::shared_ptr<TextChatData> > msgdata);
    QMap<int,QListWidgetItem*>_chat_items_added;
    std::vector<QString> strs = {
        "hello world!",
        "Great job on the presentation!",
        "Looking forward to the next update.",
        "Thanks for the helpful information.",
        "I appreciate your hard work on this.",
        "Can't wait to see what's next.",
        "Keep up the excellent work!",
        "I learned a lot from your post.",
        "Your insights are always valuable.",
        "The design is really impressive.",
        "I agree with your perspective on this issue.",
        "Your explanation made everything clear."
    };
    std::vector<QString> names = {
        "Wu",
        "Alice",
        "Bob",
        "Li",
        "David",
        "Zhang",
        "Eva",
        "Chen",
        "Frank",
        "Grace",
        "Liu"
    };
    std::vector<QString> heads = {
        ":/images/head_1.jpg",
        ":/images/head_2.jpg",
        ":/images/head_3.jpg",
        ":/images/head_4.jpg",
        ":/images/head_5.jpg",
        ":/images/head_6.jpg",
        ":/images/head_7.jpg",
        ":/images/head_8.jpg",
        ":/images/head_9.jpg",
        ":/images/head_12.jpg"
    };
    QList<StateWidget*>_lb_list;

private slots:
    void slot_loading_contact_user();
    void slot_loading_char_user();
    void slot_side_chat();
    void slot_side_contact();
    void slot_text_changed(const QString& str);
    void slot_apply_friend(std::shared_ptr<AddFriendApply> apply);
    void slot_add_auth_friend(std::shared_ptr<AuthInfo>);
    void slot_auth_rsp(std::shared_ptr<AuthRsp>);
    void slot_jump_chat_item(std::shared_ptr<SearchInfo> si);
    void slot_friend_info_page(std::shared_ptr<UserInfo>user_info);
    void slot_switch_apply_friend_page();
    void slot_jump_chat_item_from_infopage(std::shared_ptr<UserInfo>user_info);
    void slot_item_clicked(QListWidgetItem*item);
    void slot_append_send_chat_msg(std::shared_ptr<TextChatData>msgdata);
    void slot_text_chat_msg(std::shared_ptr<TextChatMsg>msg);
};

#endif // CHATDIALOG_H
